#!/usr/bin/env bash

if (( ${rvm_trace_flag:=0} == 2 ))
then
  set -x
  export rvm_trace_flag
fi

rvm_base_except="selector"

source "$rvm_scripts_path/base"
source "$rvm_scripts_path/functions/build"
source "$rvm_scripts_path/functions/pkg"

set +o errexit

# Tools to make managing ruby dependencies inside of rvm easier.
args=($*)
action="${args[0]:-""}"
library="${args[1]:-""}"
args="$(echo ${args[@]:2})"

rvm_warn "
Beware, 'rvm pkg ...' is deprecated, read about the new autolibs feature: 'rvm help autolibs'.
"

if [[ -n "$library" ]]
then
  case $library in
    readline|iconv|curl|openssl|zlib|autoconf|ncurses|pkgconfig|gettext|glib|mono|llvm|libxml2|libxslt|libyaml|epel)
      __rvm_setup_compile_environment ${library}
      install_${library}
      ;;
    ree_dependencies)
      for i in zlib ncurses readline openssl iconv
      do
        (
          __rvm_setup_compile_environment ${i}
          install_${i}
        )
      done
      ;;
    *)
      rvm_error "Package '${library}' is unknown."
      ;;
  esac

  exit $?
elif [[ "$action" == remove ]]
then
  rvm_log "Removing '$rvm_usr_path' ..."
  __rvm_rm_rf "$rvm_usr_path" &&
    rvm_log "Removed" ||
    rvm_error "Failed"
else
  rvm_help pkg
  exit 1
fi
